<?php
/**
 * Created by PhpStorm.
 * DateTime: 2020/11/3 9:06
 * Intro:
 */

namespace addons\podunk\model;
use app\common\library\Auth;

use think\Model;

class DeviceGroup extends Model
{
    protected $name = 'podunk_device_group';

    protected $autoWriteTimestamp = 'int';

    protected $createTime = 'createtime';

    protected $updateTime = '';

    protected $append = [];

    public static function getDeviceGroupList($search, $pageSize)
    {
        if($search){
            $where = [
                'name'=>['LIKE',"%".$search."%"],
            ];
        }else{
            $where = [];
        }

        $deviceGroupList = self::where(['user_id'=>Auth::instance()->id])->where(function($query) use($where){
            $query->whereOr($where);
        })->order('id desc')->paginate($pageSize);

        if($deviceGroupList){
            return $deviceGroupList;
        }
        return null;
    }
}